package com.wlyuan.open.domain.source.dispatcher.conversion;

import com.wlyuan.open.OpenBaseSyncDTO;
import com.wlyuan.open.dto.*;
import com.wlyuan.open.dto.tenant.OpenCompanyTenantSyncDTO;
import com.wlyuan.open.dto.tenant.OpenDriverTenantSyncDTO;
import com.wlyuan.open.dto.tenant.OpenTenantRelationSyncDTO;
import com.wlyuan.open.dto.top.OpenTopExtensionOrderSyncDTO;
import com.wlyuan.open.dto.transport.OpenTransportRelationSyncDTO;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * @author lijing
 * @description
 */
@Service
@Slf4j
public class OpenDispatcherConverter {

    private final Map<Class<?>, OpenDispatcherConversion> CONVERT = new HashMap<>();

    public OpenDispatcherConverter(OpenDispatcherUserConversion userConversion,
                                   OpenDispatcherConsigneeConversion consigneeConversion,
                                   OpenDispatcherContractConversion contractConversion,
                                   OpenDispatcherCustomerConversion customerConversion,
                                   OpenDispatcherDriverConversion driverConversion,
                                   OpenDispatcherBillConversion financeConversion,
                                   OpenDispatcherGoodsConversion goodsConversion,
                                   OpenDispatcherCarrierConversion carrierConversion,
                                   OpenDispatcherOrderConversion orderConversion,
                                   OpenDispatcherVehicleConversion vehicleConversion,
                                   OpenDispatcherTransportConversion transportConversion,
                                   OpenDispatcherCompanyTenantConversion companyTenantConversion,
                                   OpenDispatcherDriverTenantConversion driverTenantConversion,
                                   OpenDispatcherTenantRelationConversion tenantRelationConversion,
                                   OpenDispatcherCombineConversion combineConversion,
                                   OpenDispatcherTemplateConversion templateConversion,
                                   OpenDispatcherQuotationConversion quotationConversion,
                                   OpenDispatcherPayConversion payConversion,
                                   OpenDispatcherRelationConversion relationConversion,
                                   OpenDispatcherTransportRelationConversion transportRelationConversion,
                                   OpenDispatcherCombineQuotationConversion combineQuotationConversion,
                                   OpenDispatcherTopExtensionConversion topExtensionConversion) {
        CONVERT.put(OpenUserSyncDTO.class, userConversion);
        CONVERT.put(OpenConsigneeSyncDTO.class, consigneeConversion);
        CONVERT.put(OpenContractSyncDTO.class, contractConversion);
        CONVERT.put(OpenCustomerSyncDTO.class, customerConversion);
        CONVERT.put(OpenDriverSyncDTO.class, driverConversion);
        CONVERT.put(OpenBillSyncDTO.class, financeConversion);
        CONVERT.put(OpenGoodsSyncDTO.class, goodsConversion);
        CONVERT.put(OpenCarrierSyncDTO.class, carrierConversion);
        CONVERT.put(OpenOrderSyncDTO.class, orderConversion);
        CONVERT.put(OpenVehicleSyncDTO.class, vehicleConversion);
        CONVERT.put(OpenTransportSyncDTO.class, transportConversion);
        CONVERT.put(OpenCompanyTenantSyncDTO.class, companyTenantConversion);
        CONVERT.put(OpenDriverTenantSyncDTO.class, driverTenantConversion);
        CONVERT.put(OpenTenantRelationSyncDTO.class, tenantRelationConversion);
        CONVERT.put(OpenCombineSyncDTO.class, combineConversion);
        CONVERT.put(OpenTemplateSyncDTO.class, templateConversion);
        CONVERT.put(OpenQuotationSyncDTO.class, quotationConversion);
        CONVERT.put(OpenPaySyncDTO.class, payConversion);
        CONVERT.put(OpenRelationSyncDTO.class, relationConversion);
        CONVERT.put(OpenTransportRelationSyncDTO.class, transportRelationConversion);
        CONVERT.put(OpenCombineQuotationSyncDTO.class, combineQuotationConversion);
        CONVERT.put(OpenTopExtensionOrderSyncDTO.class, topExtensionConversion);
    }


    public void convert(OpenBaseSyncDTO source) {
        var conversion = CONVERT.get(source.getClass());
        Optional.ofNullable(conversion).ifPresent(c -> c.convert(source));
    }
}
